import lombok.Data;
import lombok.SneakyThrows;
import org.apache.poi.ss.usermodel.IndexedColors;
import user.zc.excel.data.style.IStyle;
import user.zc.helper.ExcelAssistant;
import user.zc.helper.IExcelMode;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @author zhouchuang
 * @date 2024-10-11 12:55:27
 */

@Data
@ExcelAssistant(title = "原始提供的内容",column = @ExcelAssistant.Style(font = @ExcelAssistant.Style.Font(bold = true,height = (short)18)))
public class TableInfo implements IExcelMode<TableInfo> {
    @ExcelAssistant(title = "表英文名",cell = @ExcelAssistant.Style(wrapText = true), column = @ExcelAssistant.Style(color = 44,width = 6000),rowSpanIfSameValue = true)
    public String enName;
   /* @ExcelAssistant(title = "表中文描述",column = @ExcelAssistant.Style(color = 44,width = 6000),rowSpanIfSameValue = true)
    public String zhName;*/
    @ExcelAssistant(title = "列名",column = @ExcelAssistant.Style(color = 44,width = 6000))
    public String columnName;
    @ExcelAssistant(title = "列类型",column = @ExcelAssistant.Style(color = 44,width = 4000))
    public String columnDateType;
    @ExcelAssistant(title = "列描述",column = @ExcelAssistant.Style(color = 44,width = 10000),cell = @ExcelAssistant.Style(alignment=0))
    public String columnRemark;


    private static AtomicInteger rowIndex = new AtomicInteger(0);
    private static AtomicReference<String> lastTableName  = new AtomicReference<>("");
    private static short[] colors = new short[]{IndexedColors.GREY_25_PERCENT.index,IndexedColors.GREY_50_PERCENT.index};
    @Override
    @SneakyThrows
    public IStyle.StyleInfo style(Integer i,TableInfo item,String name, Object value) {
        IStyle.StyleInfo styleInfo = IStyle.StyleInfo.newEmpty();
        if(!item.getEnName().equals(lastTableName.get())){
            rowIndex.incrementAndGet();
            lastTableName.set(item.getEnName());
        }
        styleInfo.setColor(colors[rowIndex.get()%2]);
        return styleInfo;
    }
}
